/*
* Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Implementation of the ECom interface for NFC External
*               Content Handler interface.
*/

#include "contenthandler.h"

// ---------------------------------------------------------------------------
// Symbian two-phased constructor.
// ---------------------------------------------------------------------------
//
CContentHandler* CContentHandler::NewL()
    {
    CContentHandler* self = new (ELeave) CContentHandler;
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );

    return self;
    }

// ---------------------------------------------------------------------------
// C++ destructor.
// ---------------------------------------------------------------------------
//
CContentHandler::~CContentHandler()
    {
    // Empty implementation. This default implementation does not instantiate
    // anything, so there is nothing to delete on destruction.
    }

// ---------------------------------------------------------------------------
// From base class CNfcCH, NDEF message handling function.
// ---------------------------------------------------------------------------
//
void CContentHandler::HandleNdefMessage(
    TRequestStatus& aRequestStatus,
    CNdefMessage* aMessage )
    {
    TRequestStatus* requestStatus = &aRequestStatus;
    *requestStatus = KRequestPending;

    // As this interface function is declared as non-leaving we wrap the
    // actual handling of the message in a TRAP.
    TRAPD( error, HandleNdefMessageL(aMessage) );

    User::RequestComplete( requestStatus, error );
    }

// ---------------------------------------------------------------------------
// From base class CNfcCH, NDEF message handling cancellation function.
// ---------------------------------------------------------------------------
//
void CContentHandler::HandleNdefMessageCancel()
    {
    // Empty implementation. This default implementation does all message
    // processing synchronously in the HandleNdefMessage() function, which
    // cannot be cancelled. A more complex message handler should employ a
    // true active object for the message processing, in which case this
    // function should call Cancel() for said active object.
    }

// ---------------------------------------------------------------------------
// C++ constructor.
// ---------------------------------------------------------------------------
//
CContentHandler::CContentHandler() : CNfcCH()
    {
    // Empty implementation. This default implementation has no member
    // variables, so there is nothing to initialize on construction.
    }

// ---------------------------------------------------------------------------
// Symbian second phase constructor.
// ---------------------------------------------------------------------------
//
void CContentHandler::ConstructL()
    {
    // Empty implementation. This default implementation requires no leaving
    // calls to be made on construction.
    }

// ---------------------------------------------------------------------------
// Potentially leaving version of the NDEF message handling function.
// ---------------------------------------------------------------------------
//
void CContentHandler::HandleNdefMessageL( CNdefMessage* aMessage )
    {
    CleanupStack::PushL( aMessage );

    // Process message here. It's valid to hold on to the message if necessary.
    // There is no need to destroy it before returning from this function. But
    // the ownership has been transferred to this class by the NFC External
    // Content Handler framework, so we have to make sure the message instance
    // passed in does get released eventually.

    CleanupStack::PopAndDestroy( aMessage );
    }
